﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using SignInServices.Code;
using System.ServiceModel.Activation;
using SignInServices.Common;

namespace SignInServices.Service
{
    public class SSO : ISSO
    {

        #region ISSO Members

        public void CreateUser(string userName, string password, string eMail, bool isActive)
        {
            SSOFederationHelper.FederationObject.CreateUser(userName, password,eMail,isActive);
        }

        public void DeleteUser(string userName)
        {
            SSOFederationHelper.FederationObject.DeleteUser(userName);
        }

        public bool UserExists(string userName)
        {
            return SSOFederationHelper.FederationObject.UserExists(userName);
        }

        public bool ChangePassword(string userName, string oldPaassword, string newPassword)
        {
            return SSOFederationHelper.FederationObject.ChangePassword(userName, oldPaassword, newPassword);
        }

        public IList<AuthenticatedUser> GetUsers(int index, int count)
        {
            return SSOFederationHelper.FederationObject.GetUsers(index, count).Cast<AuthenticatedUser>().ToList();
        }

        public AuthenticatedUser GetUserByName(string userName)
        {
            return (AuthenticatedUser)SSOFederationHelper.FederationObject.GetUserByName(userName);
        }

        public AuthenticatedUser GetUserByEmail(string emailAddress)
        {
            return (AuthenticatedUser)SSOFederationHelper.FederationObject.GetUserByEmail(emailAddress);
        }

        public AuthenticatedUser GetUserByID(int id)
        {
            return (AuthenticatedUser)SSOFederationHelper.FederationObject.GetUserByID(id);
        }

        public List<AuthenticatedUser> FindUsersByEmail(string EmailAddress)
        {
            return SSOFederationHelper.FederationObject.FindUsersByEmail(EmailAddress).Cast<AuthenticatedUser>().ToList();
        }

        public List<AuthenticatedUser> FindUsersByName(string UserName)
        {
            return SSOFederationHelper.FederationObject.FindUsersByName(UserName).Cast<AuthenticatedUser>().ToList();
        }

        public bool SignIn(string userName, string password)
        {
            return SSOFederationHelper.FederationObject.SignIn(userName, password);
        }

        public void SignOut(string userName)
        {
            SSOFederationHelper.FederationObject.SignOut(userName);
        }

        public bool IsAuthenticated(string userName)
        {
            return SSOFederationHelper.FederationObject.IsAuthenticated(userName);
        }

        public Common.PasswordResetResultType ResetPassword(string emailAddress)
        {
            return SSOFederationHelper.FederationObject.ResetPassword(emailAddress);
        }

        public int GetOnlineCount()
        {
            return SSOFederationHelper.FederationObject.GetOnlineUsersCount();
        }

        public void UpdateUser(string userName, string password, string eMail, bool isActive)
        {
            SSOFederationHelper.FederationObject.UpdateUser(userName, password, eMail, isActive);
        }

        #endregion
    }
}
